/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { Children } from "react";

const MapWrapper = props => {
  const { children, style, className, __map__ } = props;
  return (<div
    style={style}
    className={className}
  >
    {
      Children.map(children, (child) => {
        if (child) {
          const cType = child.type;
          /* 针对下面两种组件不注入地图相关属性
           * 1. 明确声明不需要注入的
           * 2. DOM 元素
           */
          if (cType.preventAmap || (typeof cType === "string")) {
            return child;
          }
          return React.cloneElement(child, {
            __map__
          });
        }
        return child;
      })
    }
  </div>);
};

export default MapWrapper;